<?php

namespace App\Http\Controllers\Innerend;


use App\Models\Course;
use App\Models\Event;
use App\Models\SiteInfo;
use App\Models\Student;
use App\Models\User;

class SelectorController extends BaseController
{

    // 搜索  页面ajax搜索操作
    public function initialize()
    {
        parent::initialize();
    }

    // 搜索用户
    public function user()
    {
        $keyword = $this->optLogic()->getData('keyword', null, 'trim');
        $userDb  = new User();
        $where   = [['nickname', 'like', "%$keyword%"]];
        $lists   = $userDb->where($where)->select(['id', 'nickname' => 'username'])->get();

        return $this->success($lists);
    }

    // 搜索活动
    public function event()
    {
        $keyword = $this->optLogic()->getData('keyword', null, 'trim');
        $eventDb = new Event();
        $where   = [['event_name', 'like', "%$keyword%"]];
        $lists   = $eventDb->where($where)->get();

        return $this->success($lists);
    }

    // 搜索课程
    public function course()
    {
        $keyword = $this->optLogic()->getData('keyword', null, 'trim');
        $eventDb = new Course();
        $where   = [['name', 'like', "%$keyword%"]];
        $lists   = $eventDb->where($where)->get();

        return $this->success($lists);
    }

    // 搜索：学员
    public function student()
    {
        $keyword = $this->optLogic()->getData('keyword', null, 'trim');
        $eventDb = new Student();
        $where   = [['person_name', 'like', "%$keyword%"]];
        $lists   = $eventDb->where($where)->get();

        return $this->success($lists);
    }


}


